#include <iostream>

using namespace std;

class Node
{
public:
    int data;
    Node *next;

    Node(int da = 0, Node *p = NULL)
    {
        this->data = da;
        this->next = p;
    }
};

class single_list
{
private:
    /* data */
    Node *head, *tail;
    int size;

public:
    single_list(/* args */);
    ~single_list();
    void Output();
    void Insert(int data);
    void Delete(int data);
    void Search(int pos);
    void Modify(int pos, int data);
};

single_list::single_list(/* args */)
{
    head = tail = nullptr;
    size = 0;
}

single_list::~single_list()
{
    delete head;
    delete tail;
}

void single_list::Insert(int data)
{
    if (!head)
    {
        head = tail = new Node(data);
        head->next = NULL;
        tail->next = NULL;
    }
    else
    {
        Node *p = new Node(data);
        tail->next = p;
        tail = p;
        tail->next = NULL;
    }
    size++;
}

void single_list::Output()
{
    Node *p = head;
    while (p != NULL)
    {
        cout << p->data << " \a";
        p = p->next;
    }
    cout << endl;
}

void single_list::Search(int data)
{

    Node *p = head;
    if (p == NULL)
    {
        cout << "Sorry, The List is Empty!" << endl;
        return;
    }
    int count = 0;
    while (p != NULL && p->data != data)
    {
        p = p->next;
        count++;
    }

    if (count >= size)
    {
        cout << "not find " << endl;
    }
    else
    {
        cout << "the value you want to search is at position " << count + 1 << endl;
    }
}

void single_list::Delete(int data)
{
    Node *p = head, *q = head;
    int pos = 0;
    if (p == NULL)
    {
        cout << "Sorry, The List is Empty!" << endl;
        return;
    }

    while (p != NULL && p->data != data)
    {
        q = p;
        p = p->next;
        pos++;
    }
    if (pos < size)
    {
        size--;
        q->next = p->next;
        cout << "The Deletion Operation had been finished!" << endl;
    }
    else
    {
        cout << "The Deletion Operation not find " << endl;
    }
}

void single_list::Modify(int pos, int data)
{
    Node *p = head;
//    cout << "size"<<size << endl;
    if (!p)
    {
        cout << "Sorry, The List is Empty!" << endl;
        return;
    }

    if (pos >= size)
    {
        cout << "the pos is not find" << endl;
    }
    else
    {
        for (int i = 0; i <pos; i++)
        {
            p = p->next;
        }
        p->data = data;
        cout << "modify success" << endl;
    }
}

int main()
{
    single_list l1;
    l1.Insert(1);
    l1.Insert(2);
    l1.Insert(5);
    l1.Output();
    l1.Search(6);
    l1.Delete(2);
    l1.Output();
    l1.Delete(6);
    l1.Output();
    l1.Modify(1, 3);
    l1.Output();
}